import request from '@/utils/request'
import { getToken } from '@/utils/auth'

// 获取文章分类列表
export function getArtCate () {
  return request({
    url: '/my/cate/list',
    method: 'GET',
    headers: {
      Authorization: `${getToken()}`
    }
  })
}

// 添加文章分类列表
export function addArtCate (data) {
  return request({
    url: '/my/cate/add',
    method: 'POST',
    headers: {
      Authorization: `${getToken()}` // 401错误
      // 'Content-Type': 'application/x-www-form-urlencoded'
    },
    data
  })
}

// 获取文章分类详情
export function getCate (id) {
  return request({
    url: `/my/cate/info?id=${id}`,
    method: 'GET',
    headers: {
      Authorization: `${getToken()}`
    }
  })
}

// 更改文章分类列表
export function editArtCate (data) {
  return request({
    url: `/my/cate/info?id=${data.id}`,
    method: 'PUT',
    headers: {
      Authorization: `${getToken()}`
    },
    data
  })
}

// 删除文章分类列表
export function delArtCate (id) {
  return request({
    url: `/my/cate/del?id=${id}`,
    method: 'DELETE',
    headers: {
      Authorization: `${getToken()}`
    }
  })
}

// 获取文章分类列表
export function getArtList (pagenum, pagesize) {
  return request({
    url: '/my/article/list',
    method: 'GET',
    headers: {
      Authorization: `${getToken()}`
    },
    params: {
      pagenum, pagesize
    }
  })
}

// 添加文章
export function addArt (data) {
  return request({
    url: '/my/article/add',
    method: 'POST',
    headers: {
      Authorization: `${getToken()}`, // 401错误
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

// 删除文章列表
export function delArtList (id) {
  return request({
    url: `/my/article/info?id=${id}`,
    method: 'DELETE',
    headers: {
      Authorization: `${getToken()}`
    }
  })
}
